package com.koyi0000.mq.rabbit.trans;

import com.koyi0000.mq.BO.User;
import com.koyi0000.mq.DO.UserDO;
import com.koyi0000.mq.rabbit.DO.UserDO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author koyi0000
 * Description  Date 2020/9/15 16:41
 **/
public class UserTrans {

    public static User toBO(UserDO userDO) {
        User user = new User();
        user.setUserId(userDO.getUserId());
        user.setAge(userDO.getAge());
        user.setGender(userDO.getGender());
        user.setUserName(userDO.getUserName());
        user.setGmtCreate(userDO.getGmtCreate());
        user.setGmtModified(userDO.getGmtModified());
        return user;
    }

    public static List<User> toBOs(List<UserDO> userDOS) {
         if (userDOS == null || userDOS.isEmpty()) {
              return null;
         }
         return userDOS.stream().map(userDO -> toBO(userDO)).collect(Collectors.toList());
    }

    public static UserDO toDO(User user) {
        UserDO userDO = new UserDO();
        userDO.setUserId(user.getUserId());
        userDO.setAge(user.getAge());
        userDO.setGender(user.getGender());
        userDO.setUserName(user.getUserName());
        userDO.setGmtCreate(user.getGmtCreate());
        userDO.setGmtModified(user.getGmtModified());
        return userDO;
    }

    public static List<UserDO> toDOs(List<User> users) {
        if (users == null || users.isEmpty()) {
            return null;
        }
        return users.stream().map(user -> toDO(user)).collect(Collectors.toList());
    }

}
